Preview - Intro To Netlogo Programming For Educators

Creating and Moving Turtles


This page will introduce you to turtles, one of the most important things in NetLogo. Follow along with the steps below.

 

Notes if you are using NetLogo Web:

  • You might want to open NetLogo Web in a new window here so that you don't have to keep scrolling between the NetLogo interface and the questions below. 
  • At the top of the NetLogo Web interface, there is text that say "Commands and Code:"  and then says either "Right Side", or "Bottom".  You can click that text to toggle between the two options. 


Questions

Please answer the questions below.

Creating and Moving Turtles

Click the Command Center and create a turtle by typing create-turtles 1. This created 1 turtle. Because this is something you do a lot in NetLogo, there is an abbreviation: crt. Try typing crt 50. That created 50 turtles.

The turtles are all facing random directions by default. What do you think it will look like if they all move forward the same distance? Type your answer below and then we'll try it in the next question.

 

Note: if you are using NetLogo Web, the Command Center is the first horizontal purple bar. If you are using NetLogo Desktop it is at the bottom of the interface.

 


Moving Turtles

Now let's ask the turtles to move. In the Command Center, type ask turtles [forward 10]. There is an abbreviation for this one too. You can just type ask turtles [fd 10], and it will do the same thing. To clear everything away, type clear-all, or ca for short (not every command has an abbreviation, but a lot of the most common ones do).

What does it look like when you create a bunch of turtles and ask them to all move forward the same distance? Why is this?

 


What do you think it will look like if you create a bunch of turtles and then have them each move forward a random distance instead of the same distance?


The command random number will produce a random integer greater than 0 and less than number. So random 10 will output a random integer greater than 0 and less than 10. The command random-float number does the same thing, except the output will be a decimal number instead of an integer.

Try creating a bunch of turtles and asking them to move forward a random distance.  What does it look like?  Does it look different if you use random vs random-float? Does it look different as you add more turtles? Try to explain why you see what you do for each question. 


Emergence

The patterns you saw in the previous questions are a simple example of "emergent phenomena." You never told the turtles to make the shape they did. Each turtle just followed a simple command of moving forward, but a macro-level pattern emerged from all the individual actions. We will see many more examples of emergent phenomena. Can you think of an example of an emergent phenomenon? What about something that isn't an emergent phenomenon?


Moving individual turtles and turning

  • You can also ask individual turtles to do things. Try typing ask turtle 1 [fd 5]. Each turtle has a number. Go ahead and move a few turtles individually. 
  • To have turtles turn, you have to ask them to turn a number of degrees. For example, rt 90  to turn right by 90 degrees, or lt 30 to turn left by 30 degrees (rt stands for right turn and lt for left turn). Try asking some turtles individually and as a group to turn and move.

Using just the commands you've learned, how might you make a turtle move in a circle?


If you had any issues on this page, describe them below. If not, type something like "no problems" and continue on.


Notes

These notes will appear on every page in this lesson so feel free to put anything here you'd like to keep track of.